/*************************************************/
#include "str_hex.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/*************************************************/
void hex_to_string(uint8_t *hex_buf, uint16_t length, char* char_buf)
{
    for(uint8_t i = 0; i< length; i++)
    {
				sprintf(char_buf, "%02X", *hex_buf);
        char_buf +=2;
        hex_buf++;
    }

    *char_buf = '\0';
}
/*************************************************/
uint16_t string_to_hex(char *str, char *out)
{
    char *p = str;
		char high = 0, low = 0;
		int tmplen = strlen(p), cnt = 0;
		tmplen = strlen(p);
		while(cnt < (tmplen / 2))
		{
				high = ((*p > '9') && ((*p <= 'F') || (*p <= 'f'))) ? *p - 48 - 7 : *p - 48;
			 low = (*(++ p) > '9' && ((*p <= 'F') || (*p <= 'f'))) ? *(p) - 48 - 7 : *(p) - 48;
			 out[cnt] = ((high & 0x0f) << 4 | (low & 0x0f));
			 p ++;
			 cnt ++;
	 }
	 if(tmplen % 2 != 0) out[cnt] = ((*p > '9') && ((*p <= 'F') || (*p <= 'f'))) ? *p - 48 - 7 : *p - 48;
	 
	 return tmplen / 2 + tmplen % 2;
}
/***************************END OF FILE*****************************/

